package com.example.train.common.config.security;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.AntPathMatcher;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 用于配置白名单资源路径
 */
@Getter
@Setter
@ConfigurationProperties(prefix = "secure.ignored")
public class IgnoreUrlsConfig {
    private List<String> urls = new ArrayList<>();


    public boolean isIgnoreForRequest(HttpServletRequest request){
        AntPathMatcher antPathMatcher = new AntPathMatcher();

        String servletPath = request.getServletPath();

        for (String url : urls) {
            if (antPathMatcher.match(url, servletPath)) {
                return true;
            }
        }
        return false;
    }
}
